<layout name="popup" />
<block name="content">
	<input type="hidden" name="ajax" id="ajax" value="1">
	<div class="popup-header">
		<h1>添加</h1>
		<i class="mid"></i>
		<a class="btn btn-normal" onclick="save();">确定</a>
		<a class="btn btn-return" onclick="close_popup();">取消</a>
	</div>
	<div class="popup-body">
		<div class="popup-body-scroll">
			<div class="popup-content">
				<form id="form_data" name="form_data" method="post" >
					<input type="hidden" name="id" id="id" >
					<input type="hidden" name="opmode" id="opmode" value="add">
					<input type="hidden" name="admin" id="admin">
					<input type="hidden" name="write" id="write">
					<input type="hidden" name="read" id="read">
					<input type="hidden" name="controller" value="{$controller}">
					<div class="box">
						<label class="input-label" for="name">名称*：</label>
						<input class="input" type="text" id="name" name="name" check="required" info="请输入名称">
					</div>
					<if condition="$has_pid">
						<div class="box">
							<label class="input-label" for="folder_name">父节点*：</label>
							<div class="input-box">
								<input type="hidden" name="pid" id="pid">
								<input name="folder_name" class="input val" id="folder_name" type="text" info="请选择父节点" check="required" />
								<a class="add-on" onclick="select_pid();"> 选择 </a>
							</div>
						</div>
					</if>
					<div class="box">
						<label class="input-label" for="folder_name">管理：</label>
						<div id="admin_list" class="multi-select-box">
							<span class="data-list"></span>
							<input class="letter" type="text" >
							<label></label>
							<div class="search hidden">
								<ul></ul>
							</div>
						</div>
						<a class="add-on" onclick="select_auth();"><i class="fa fa-user"></i></a>
					</div>
					<div class="box">
						<label class="input-label" for="folder_name">编辑：</label>
						<div id="write_list" class="multi-select-box">
							<span class="data-list"></span>
							<input class="letter" type="text" >
							<label></label>
							<div class="search hidden">
								<ul></ul>
							</div>
						</div>
						<a class="add-on" onclick="select_auth();"><i class="fa fa-user"></i></a>
					</div>
					<div class="box">
						<label class="input-label" for="folder_name">读取：</label>
						<div id="read_list" class="multi-select-box">
							<span class="data-list"></span>
							<input class="letter" type="text" >
							<label></label>
							<div class="search hidden">
								<ul></ul>
							</div>
						</div>
						<a class="add-on" onclick="select_auth();"><i class="fa fa-user"></i></a>
					</div>
					<div class="box">
						<label class="input-label" for="sort">排序：</label>
						<div class="input-block w10">
							<input class="input" type="text" id="sort" name="sort" >
						</div>
					</div>
					<div class="box">
						<label class="input-label" for="sort">状态：</label>
						<select class="select w10"  name="is_del" id="is_del">
							<option value="0">启用</option>
							<option value="1">禁用</option>
						</select>
						<i class="icon"></i>
					</div>
				</form>
			</div>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		var index = parent.layer.getFrameIndex(window.name);
		layui.use(['global'], function() {
			var $ = layui.jquery;
			var fn = {
				save : function() {
					var admin = [];
					var write = [];
					var read = [];
					$("#admin_list span.data-list a").each(function() {
						$this = $(this);
						name = $this.text();
						data = $this.attr('data');
						admin.push({
							name : name,
							data : data
						});
					});
					$("#write_list span.data-list a").each(function() {
						$this = $(this);
						name = $this.text();
						data = $this.attr('data');
						write.push({
							name : name,
							data : data
						});
					});
					$("#read_list span.data-list a").each(function() {
						$this = $(this);
						name = $this.text();
						data = $this.attr('data');
						read.push({
							name : name,
							data : data
						});
					});

					$("#admin").val(JSON.stringify(admin));
					$("#write").val(JSON.stringify(write));
					$("#read").val(JSON.stringify(read));

					send_form('form_data', '{:url("system_folder/save")}', '', function(ret) {
						if (ret.status == 1) {
							parent.layer.msg(ret.info, {
								time : 1200
							}, function() {
								parent.layer.close(index);
								parent.location.reload(true);
							});
						} else {
							parent.layer.msg(ret.info);
							return false;
						};
					});
				},
				close_popup : function() {
					parent.layer.close(index);
				},
				select_auth : function() {
					winopen("{:url('popup/auth')}", 560, 470);
				},
				select_pid : function() {
					winopen("{:url('system_folder/select_pid',array('controller'=>$controller))}", 560, 470);
				},
			};
			win_exp(fn);
			//保存后关闭
			$('#save').on('click', function() {

			});
		});

	</script>
</block>